package com.gs.core.service.impl;

import java.util.Collection;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.gs.core.domain.Action;
import com.gs.core.repository.ActionRepository;
import com.gs.core.service.ActionService;
import com.gs.core.service.dao.ActionDAO;

@Service(value="actionService")
public class ActionServiceImpl implements ActionService{

	@Autowired
	ActionRepository actionRepository;
	
	@Autowired
	ActionDAO actionDAO;
	
	
	public List<Action> findAll() {
		int actionCount = actionDAO.getActionCount() ;
		System.out.println("There are " + actionCount + " actions.");
		if(actionCount>0){
			Collection<Action> actions = actionDAO.getActions();
			int counter=1;
			for(Action a:actions){
				System.out.println("Action "+(counter++)+ ". "+a);
			}
		}
		return actionRepository.findAll();
	}

	public Map getAction(int id){
		return actionDAO.getAction(id);
	}
	
	public List<Map<String, String>> getLoginActions(){
		return actionDAO.getLoginActions();
	}
	
	public Action findById(Long id) {
		return actionRepository.findOne(id);
	}
	@Transactional(propagation=Propagation.MANDATORY)
	public Action saveOrUpdate(Action entity) {
		return actionRepository.save(entity);
	}
	@Transactional(propagation=Propagation.MANDATORY)
	public void delete(Action entity) {
		actionRepository.delete(entity);
	}
	@Transactional(propagation=Propagation.MANDATORY)
	public void deleteAll() {
		actionRepository.deleteAll();
	}

}
